class ReasonNode extends MyNode{
    constructor($state='new',...obj){
        super('Reason',$state,{
            name:"原因描述",
            probability:0.2,
            frequency:{},
            outId:0
        },...obj);
        delete this.frequency["undefined"];
    }

    getText(){
        let sIndex = '';
        if(this.outId!=0)
            sIndex = `<${this.outId}>`;
        return `原因${sIndex}：${this.name}`;
    }

    defaultFrequency(featureId){
        this.frequency = this.frequency || {};
        if (!this.frequency[`${featureId}`]){
            this.frequency[`${featureId}`] = 0
        }
        return this.frequency;
    }

    getTemplate(edge,g){
        return `
 <div class="form-group">
    <label class="col-sm-2 control-label">导出ID</label>
    <div class="col-sm-10">
    <input data-ng-model-options="{updateOn:'default blur',debounce:{default:5000,blur:0}}" type="text" class="form-control" data-ng-model="graph.getNode('${this.id}').outId" placeholder="用于导出的ID">
    </div>
 </div>
 <div class="form-group">
    <label class="col-sm-2 control-label">原因描述</label>
    <div class="col-sm-10">
    <textarea data-ng-model-options="{updateOn:'default blur',debounce:{default:5000,blur:0}}" rows="3" class="form-control" data-ng-model="graph.getNode('${this.id}').name" placeholder="请输入原因描述"></textarea>
    </div>
 </div>
 <div class="form-group">
    <label class="col-sm-2 control-label">故障到原因的概率</label>
    <div class="col-sm-10">
    <input data-ng-model-options="{updateOn:'default blur',debounce:{default:5000,blur:0}}" type="text" class="col-sm-10 form-control" data-ng-model="graph.getNode('${this.id}').probability" placeholder="请输入概率">
    </div>
 </div>
 <div class="form-group">
    <label class="col-sm-2 control-label">特征到原因的概率</label>
    <div class="col-sm-10">
    <input data-ng-model-options="{updateOn:'default blur',debounce:{default:5000,blur:0}}" type="text" class="col-sm-10 form-control" data-ng-model="graph.getNode('${this.id}').selfFrequency" placeholder="请输入概率">
    </div>
 </div>
  <div class="form-group">
 <label class="col-sm-2 control-label">操作</label>
 <p class="col-sm-10 form-control-static">
     <a class="button btn" data-ng-if="allowFeature('${this.id}')" data-ng-click="attachFeature('${this.id}')">添加特征</a>
     <a class="button btn" data-ng-if="allowFeature('${this.id}')" data-ng-click="attachGroup('${this.id}','FeatureGroup')">添加特征组</a>
     <a class="button btn" data-ng-if="allowFeature('${this.id}')" data-ng-click="attachExternalFeature('${this.id}')">添加已存在特征</a>
     <a class="button btn" data-ng-if="allowFeature('${this.id}')" data-ng-click="attachExternalGroup('${this.id}','FeatureGroup')">添加已存在特征组</a>
     <a class="btn" data-ng-if="allowComponent('${this.id}')" data-ng-click="attachComponent('${this.id}')">添加元件</a>
     <a class="btn" data-ng-if="allowComponent('${this.id}')" data-ng-click="attachGroup('${this.id}','ComponentGroup')">添加元件组</a>
     <a class="button btn"  data-ng-click="attachRunningIssue('${this.id}')">添加运行建议</a>
     <a class="button btn"  data-ng-click="attachSolution('${this.id}')">添加解决方案</a>
     &nbsp;<a class="btn" href="javascript:;" ng-click="removeEdge(${edge})">删除当前节点</a>
 </p>
</div>
`;
    }

    getReadonlyTemplate(edge,g){
        return `
 <div class="form-group">
    <label class="col-sm-2 control-label">原因描述</label>
    <p class="col-sm-10 form-control-static">${this.name}</p>
 </div>
 <div class="form-group">
    <label class="col-sm-2 control-label">概率</label>
    <p class="col-sm-10 form-control-static">${this.probability}</p>
 </div>
`
    }
}
